package de.mmis.helferlein.demo;

import java.io.IOException;

import de.mmis.core.base.event.Observable;
import de.mmis.core.base.event.Observer;
import de.mmis.core.publishsubscribe.PublishSubscribe;
import de.mmis.core.publishsubscribe.PublishSubscribeImpl;
import de.mmis.core.publishsubscribe.PublishSubscribe.PublishSubscribeException;
import de.mmis.core.publishsubscribe.filter.Filter;
import de.mmis.helferlein.demo.IntProducer.IntEvent;

/* GenericPublisher arguments:
 --gui
 --object "Consumer" "($java-object de.mmis.applications.simpleExamples.publishsubscribe.WorldstateConsumer)"
 --subscribeC "$Int >= 3 && $Float@FloatProd < 42.23" de.mmis.applications.simpleExamples.publishsubscribe.IntProducer$IntEvent "(event @EVENT_Int)"
 */
public class WorldstateConsumer {

	public void event(int number) {
		System.out.println("got number " + number);
	}

	public static void main(String[] args) throws PublishSubscribeException,
			IOException {
		PublishSubscribe ps = PublishSubscribeImpl.getInstance();
		Filter filter = Filter.parse("$Int >= 3 && $Float@FloatProd < 42.23");

		final WorldstateConsumer wsc = new WorldstateConsumer();

		ps.subscribe(IntEvent.class, filter, new Observer<IntEvent>() {
			@Override
			public void notify(Observable<? extends IntEvent> sender,
					IntEvent event) {
				wsc.event(event.getInt());
			}
		});

		System.in.read();
	}
}
